import os,sys
from pathlib import Path
import shutil

def main():
    if len(sys.argv)!=3:
        print("参数错误，请输入参数 <源根路径> <输出根路径>\n")
        exit()
    top_dir = sys.argv[1]
    output_path = sys.argv[2]
    if not os.path.isdir(top_dir) or not os.path.isdir(output_path):
        print("目标参数不是文件夹\n")
        exit()

    toplist = os.listdir(top_dir)

    for subf in toplist:
        subpath = os.path.join(top_dir, subf)
        if os.path.isdir(subpath):
            subflist = os.listdir(subpath)
            for trdf in subflist:
                trdf_parent_dir = os.path.basename(subpath)
                trdpath = os.path.join(subpath, trdf)
                if os.path.isdir(trdpath) and (trdf==f'{trdf_parent_dir}-3x4' or trdf==f'{trdf_parent_dir}-100x100'):
                    trdlist = os.listdir(trdpath)
                    for pic_file in trdlist:
                        file_ext = pic_file.rsplit('.',maxsplit=1)
                        if len(file_ext)!=2:
                            continue
                        ext = file_ext[1].lower()
                        if ext!='jpg' and ext!='jpeg' and ext!='png':
                            continue
                        fthpath = os.path.join(trdpath, pic_file)
                        shutil.move(fthpath, output_path)


if __name__ == '__main__':
    main()